package com.wangjiyuan.shiwupai.ui.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;

import com.wangjiyuan.shiwupai.R;
import com.wangjiyuan.shiwupai.base.BaseActivity;
import com.wangjiyuan.shiwupai.mine.fragment.MineFragment;
import com.wangjiyuan.shiwupai.ui.fragment.guangchi.GuangChiFragment;
import com.wangjiyuan.shiwupai.ui_food.food.FoodFragment;

public class MainActivity extends BaseActivity implements View.OnClickListener {

    private RadioButton library, homepage, my;
    private GuangChiFragment mGuangchiFargment;
    private MineFragment mMineFragment;
    private FoodFragment mFoodFragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mGuangchiFargment = new GuangChiFragment();
        mMineFragment = new MineFragment();
        mFoodFragment=new FoodFragment();
        initView();

    }

    private void initView() {
        library = (RadioButton) findViewById(R.id.library);
        homepage = (RadioButton) findViewById(R.id.homepage);
        my = (RadioButton) findViewById(R.id.my);
        library.setOnClickListener(this);
        homepage.setOnClickListener(this);
        my.setOnClickListener(this);
        getSupportFragmentManager().beginTransaction()
                .add(R.id.activity_main, mGuangchiFargment, null)
                .add(R.id.activity_main, mMineFragment, null)
                .add(R.id.activity_main,mFoodFragment,"FoodFragment")
                .hide(mMineFragment)
                .hide(mGuangchiFargment)
                .commit();
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.library:
                getSupportFragmentManager().beginTransaction()
                        .show(mFoodFragment)
                        .hide(mMineFragment)
                        .hide(mGuangchiFargment)
                        .commit();
                break;
            case R.id.homepage:
                getSupportFragmentManager().beginTransaction()
                        .show(mGuangchiFargment)
                        .hide(mMineFragment)
                        .hide(mFoodFragment)
                        .commit();
                break;
            case R.id.my:
                getSupportFragmentManager().beginTransaction()
                        .show(mMineFragment)
                        .hide(mGuangchiFargment)
                        .hide(mFoodFragment)
                        .commit();
                break;
        }
    }
}
